package com.sinopec.basemodule.model

import android.os.Parcelable
import com.google.gson.annotations.Expose
import kotlinx.android.parcel.Parcelize

/**
 * 类描述：省市区bean<br/>
 * 创建人：吴冬冬<br/>
 * 创建时间：2019/6/14 14:01 <br/>
 */
@Parcelize
data class ProvinceCityModel(
        val id: Long,
        val level: Int,
        val name: String,
        val parentId: Long,
        var subjections: List<ProvinceCityModel>,
        @Expose(serialize = false, deserialize = false) var pinyin: String = "#",
        /**
         * 是否选中
         */
        @Expose(serialize = false, deserialize = false) var isSelect: Boolean = false
) : Parcelable, Comparable<ProvinceCityModel>, Cloneable {

    companion object {
        /**
         * 国家
         */
        const val COUNTY = 0
        /**
         * 省或直辖市
         */
        const val PROVINCE = 1
        /**
         * 市或直辖市城区
         */
        const val CITY = 2
        /**
         * 区
         */
        const val AREA = 3
    }

    override fun compareTo(other: ProvinceCityModel): Int {
        val firstC = this.pinyin[0]
        val secondC = other.pinyin[0]
        if (firstC.toString() == "#") {
            return 1
        } else if (secondC.toString() == "#") {
            return -1
        } else {
//            val compareTo = this.pinyin.compareTo(o.pinyin)
            val compareTo = firstC.compareTo(secondC)
            if (compareTo == 0) {
                return if ((this.id - other.id) > 0) 1 else -1
            }
            return compareTo
        }
    }

    public override fun clone(): ProvinceCityModel {
        val clone = super.clone() as ProvinceCityModel
        val newList = mutableListOf<ProvinceCityModel>()
        clone.subjections.forEach {
            newList.add(it.clone())
        }
        clone.subjections = newList
        return clone
    }
}